<?php
$file = "fifo_x";
if (!posix_access($file,POSIX_F_OK)){
    if (posix_mkfifo($file,0666)){
        fprintf(STDOUT,"create ok\n");
    }
}

$pid = pcntl_fork();
if ($pid==0){
   $fd = fopen($file,"r+");
   $data = fread($fd,5);
   if ($data){
       fprintf(STDOUT,"read process pid=%d,recv=%s\n",getmypid(),$data);
   }
   exit(0);
}


$fd = fopen($file,"w+");
$len = fwrite($fd,"hello",5);
fprintf(STDOUT,"write process pid=%d,write len=%d\n",posix_getpid(),$len);
fclose($fd);

$pid = pcntl_wait($status);
if ($pid>0){
    fprintf(STDOUT,"exit pid=%d\n",$pid);
}